const mongoose = require("mongoose");
const baseModel = require("../base-model");
const md5 = require("../../util/md5");

// 创建User数据原型
const UserSchema = new mongoose.Schema({
  ...baseModel,
  username: {
    type: String,
    required: true,
  },
  email: {
    type: String,
    required: true,
  },
  // 密码要在设置时自动用md5加密，并且在默认查询时不出现在查询结果中
  password: {
    type: String,
    required: true,
    set: (value) => md5(value),
    select: false,
  },
  // 简介
  bio: {
    type: String,
    default: "",
  },
  // 头像
  avatar: {
    type: String,
    default: null,
  },
});

module.exports = UserSchema;
